package com.cn.jinl.utils;

import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class NumberUtil {

    public static String getPoint(double arg, int n) {
        BigDecimal b = new BigDecimal(arg);
        double result = b.setScale(n, BigDecimal.ROUND_HALF_UP).doubleValue();
        String format = "#0";
        if (n > 0) {
            format += ".";
            for (int i = 0; i < n; i++) {
                format += "0";
            }
        }
        String numStr = new DecimalFormat(format).format(new Double(result));
        return numStr;
    }

    public static String getPoint(String arg, int n) {
        if (StringUtils.isEmpty(arg)) {
            return "";
        }
        double dv = Double.parseDouble(arg);
        return getPoint(dv, n);
    }

}
